{{define "demo01/jsonindex.html"}}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/s/js/jquery-3.7.1.min.js"></script>
</head>
<body>
    我是json index
    <form >
        <input type="text" name ="username" id ="username">
        <input type="text" name ="age" id = "age">
        <span id="span"></span>
        <input type="button" value="提交" id="butt">

    </form>

    <script>
        var butt=document.getElementById("butt")


        butt.onclick = function () {
            //获取界面的数据
            var uname = document.getElementById("username").value;
            var age = document.getElementById("age").value;
            //alert(uname + age);

            //ajax调用后台代码
            $.ajax({
                url: "/postBanding",
                type: "POST",

                //ajax提交数据需要配置contentType
                contentType: "application/json",

                //JSON.stringify() 方法用于将 JavaScript 值转换为 JSON 字符串
                data: JSON.stringify({
                    "uname": uname,
                    "age": age
                }),


                //返回成功
                success: function (info) {
                    alert(info["msg"])
                  //  document.getElementById("span").innerText = info["msg"]
                }


            })

        }
    </script>


</body>
</html>
{{end}}